package socketmvc.core.processor.bean.optimizer.ret;

import socketmvc.core.context.IContext;
import socketmvc.core.packets.basic.IPacket;
import socketmvc.core.packets.basic.impl.JsonBinPacket;
import socketmvc.core.packets.basic.impl.JsonTextBody;
import socketmvc.core.packets.biz.SockFile;
import socketmvc.core.packets.biz.SockMultiFile;
import socketmvc.core.processor.bean.ProcessorMethodReturn;

import java.util.Collection;
import java.util.List;

public class DefRetSockFileCollectionValOptimizer extends DefAbstractRetOptimizer<Collection<SockFile>> {
    @Override
    public IPacket doValue(IContext context, IPacket packet, Collection<SockFile> files, JsonTextBody responseTextBody) {
        List<SockFile> sockFiles;
        if (files instanceof List<SockFile>){
            sockFiles = (List<SockFile>) files;
        }else {
            sockFiles = files.stream().toList();
        }
        SockMultiFile multiFile = new SockMultiFile(sockFiles);
        return new JsonBinPacket(responseTextBody , multiFile);
    }
}
